package vivek.project.pocketmoney.common.controls.ComboDataGridColumn
{
	import mx.collections.ArrayCollection;
	import mx.collections.ListCollectionView;
	import mx.collections.Sort;
	import mx.collections.SortField;
	import mx.controls.advancedDataGridClasses.AdvancedDataGridColumn;
	import mx.core.IFactory;
	import vivek.project.pocketmoney.admin.model.AdminConstants;

	/**
	 *  Dispatched when the ComboBox contents changes as a result of user
	 *  interaction, when the <code>selectedIndex</code> or
	 *  <code>selectedItem</code> property changes, and, if the ComboBox control
	 *  is editable, each time a keystroke is entered in the box.
	 *
	 *  @eventType mx.events.ListEvent.CHANGE
	 */
	[Event(name="change", type="mx.events.ListEvent")]
	public class AdvancedDataGridComboBoxHeaderColumn extends AdvancedDataGridColumn
	{
		public function AdvancedDataGridComboBoxHeaderColumn()
		{
			//trace(new Date().toTimeString()+"\tComboBoxHeaderColumn:ComboBoxHeaderColumn\tStart");
			super();
			width=super.width;
			//trace(new Date().toTimeString()+"\tComboBoxHeaderColumn:ComboBoxHeaderColumn\tEnd");
		}
		/**
		 *  The data provider for the combobox
		 */
		public var comboBoxDataProvider:Object;
		public var comboBoxItemRenderer:IFactory;
		public var comboHeaderText:String;
		public var comboLabelField:String;
		/**
		 *  The current combobox selectedIndex
		 */
		public var selectedIndex:int=0;
		/**
		 *  The current combobox selectedItem
		 */
		public var selectedItem:Object;
		private var _comboLabelFunction:Function;
		private var _dataField:String='data';

		public function get comboLabelFunction():Function
		{
			return _comboLabelFunction;
		}

		public function set comboLabelFunction(value:Function):void
		{
			_comboLabelFunction=value;
		}

		public function get dataProvider():Object
		{
			return comboBoxDataProvider;
		}

		public function set dataProvider(object:Object):void
		{
			var sort:Sort=new Sort();
			sort.fields=[new SortField(dataField)];
			var sorted:ArrayCollection=new ArrayCollection();
			var sortedArray:Array=new Array();
			if (object is ArrayCollection)
			{
				sorted=ArrayCollection(object);
				sorted.sort=sort;
				sorted.addItemAt(AdminConstants.ALL_STRING, 0);
				sorted.refresh();
				comboBoxDataProvider=sorted;
			}
			if (object is ListCollectionView || object is Array)
			{
				sortedArray=object as Array;
				sortedArray.sort();
				sortedArray.unshift(AdminConstants.ALL_STRING);
				comboBoxDataProvider=sortedArray;
			}
		}

	
	}
}